
package com.jiu.config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.Vector;
import org.apache.log4j.PropertyConfigurator;
import com.jiu.core.Account;

public class Config {
	private static Properties prop = null;
	private Vector<Account> accounts = null;
	static {
		PropertyConfigurator.configure("config/log4j.properties");
		prop = new Properties();
		try {
			prop.load(new FileReader("config/config.properties"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Config() {
		accounts = loadUser("config/account.txt");
		if (prop.get("http.proxyHost") != null) {
			Properties sysProp = System.getProperties();
			sysProp.setProperty("http.proxyHost", prop.getProperty("http.proxyHost"));
			sysProp.setProperty("http.proxyPort", prop.getProperty("http.proxyPort"));
		}
	}
	
	public Properties getProp() {
		return prop;
	}
	
	public Vector<Account> getAccounts() {
		return accounts;
	}
	
	private Vector<Account> loadUser(String fileName) {
		Vector<Account> accounts = new Vector<Account>();
		File file = new File(fileName);
		try {
			if (!file.exists()) {
				file.createNewFile();
			}
			InputStream in = new FileInputStream(file);
			BufferedReader br = new BufferedReader(new InputStreamReader(in, "gbk"));
			String line = "";
			while ((line = br.readLine()) != null) {
				String[] data = line.split("--");
				Account account = new Account();
				account.setQq(data[0]);
				account.setProxyQQ(data[1]);
				account.setProxyPwd(data[2]);
				account.setNickname(data[3]);
				account.setControlGroup(data[4]);
				account.setQqColor(data[5]);
				account.setFishColor(data[6]);
				if(data.length>7)
					account.setFont(data[7]);
				if(data.length>8)
					account.setLoginCode(data[8]);
				accounts.add(account);
			}
			br.close();
			in.close();
		} catch (IOException e) {
		}
		return accounts;
	}
}
